package com.yjs.ppjokedemo.ui.find;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yjs.ppjokedemo.R;
import com.yjs.ppjokedemo.adapter.LikedListAdapter;
import com.yjs.ppjokedemo.bean.LikedItem;
import com.yjs.ppjokedemo.databinding.FragmentLikedBinding;
import com.yjs.ppjokedemo.viewmodel.RecomViewModel;

import java.util.List;


public class LikedFragment extends Fragment implements LikedListAdapter.LikedInterface {

    FragmentLikedBinding mFragmentLikedBinding;
    RecomViewModel mRecomViewModel;


    public LikedFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mFragmentLikedBinding = FragmentLikedBinding.inflate(inflater,container,false);
        return mFragmentLikedBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        LikedListAdapter likedListAdapter = new LikedListAdapter( this);
        mFragmentLikedBinding.rvFindLiked.setAdapter(likedListAdapter);

        mRecomViewModel = new ViewModelProvider(requireActivity()).get(RecomViewModel.class);
        mRecomViewModel.getLiked().observe(getViewLifecycleOwner(), new Observer<List<LikedItem>>() {
            @Override
            public void onChanged(List<LikedItem> likedItems) {
                likedListAdapter.submitList(likedItems);
            }
        });

    }
}